package com.whz.composite;

import java.util.Collection;
import java.util.HashSet;

/**
 * @ClassName InstrumentedHashSet
 * @Description TODO 可以查看自从创建以来添加了多少个元素
 * @Author hong-zhi
 * @Date 2021/5/5 23:05
 * @Version 1.0
 */
public class InstrumentedHashSet<E> extends HashSet<E> {
    private int addCount = 0;
    public InstrumentedHashSet() {}
    public InstrumentedHashSet(int initCap, float loadFactor) {
        super(initCap, loadFactor);
    }

    @Override
    public boolean add(E e) {
        addCount ++;
        return super.add(e);
    }

//    @Override
//    public boolean addAll(Collection<? extends E> c) {
//        addCount += c.size();
//        return super.addAll(c);
//    }

    public int getAddCount() {
        return addCount;
    }
}
